//
//  Student.swift
//  07-FMDB基本使用
//
//  Created by J on 16/7/31.
//  Copyright © 2016年 J. All rights reserved.
//

import UIKit

class Student: NSObject {
    
    var name :String
    var age:Int
    
    
     init(name:String,age:Int) {
        self.name = name;
        self.age = age;
        
    }
    
    func insertHistory(){
        let sql = "insert into t_history(name,age) values(?,?);"
        SQLiteManager.shareInstance.db.executeUpdate(sql, withArgumentsInArray: [name,age])
    }

    class func loadStudent() {
        let sql = "select * from t_history"
      let result =   SQLiteManager.shareInstance.db.executeQuery(sql, withArgumentsInArray: nil)
        
//        SQLiteManager.shareInstance.db.inDatabase { (db) in
//            db.executeQuery(sql, withArgumentsInArray: nil)
        
//           let result =  db.executeQuery(sql, withArgumentsInArray: nil)
//            while result.next() {
//                let id =  result.intForColumn("id")
//                let name = result.stringForColumn("name")
//                let age = result.intForColumn("age")
//                
//                print("id = \(id) name = \(name) age = \(age)")
//                
//            }
//        }
        
        while result.next() {
            let id =  result.intForColumn("id")
            let name = result.stringForColumn("name")
            let age = result.intForColumn("age")
            
            print("id = \(id) name = \(name) age = \(age)")
            
        }

        
    }
    
    
}
